app.controller('loujiandaishenqingCtrl',['$scope','$http','mainService','$location',function ($scope,$http,mainService,$location) {

    var token = localStorage.getItem('token');
    mui.showLoading('正在加载','div');
    $http({
        method: "POST",
        url: mainUrl+'/tr/tr-un-confirm!findByPage.action',
        params: {
            'Authorization': token,
            'qm.state':'03' ,
            'qm.checkPersonId': JSON.parse(localStorage.getItem('userData')).pin
            // 'page': 0,
            // 'start': 1,
            // 'limit':99999


        }
    }).then(
        function(data, status, headers, config){
            console.log(data);
            for(var c=0;c<data.data.items.length;c++){
                data.data.items[c].eachFlag = false;
            }
            $scope.data = data.data.items;
            mui.hideLoading();


        },function(data, status, headers, config){
            //mui.hideLoading();

        }
    );
  //  $scope.sending = function ($event){
        //mainService.setXq(111,$event);
        //$location.path('/daiyanshouyinhuanxiangqing');
   // };

    var sendingArr = [];
    $scope.all = 1;
    $scope.clear = 2;
    $scope.changeState = function ($event) {
        $event.eachFlag = ! $event.eachFlag;
        if($event.eachFlag == true){
            sendingArr.push($event);
        }else {
            for(var i=0;i<sendingArr.length;i++){
                if($event.sid==sendingArr[i].sid){
                    sendingArr.splice(i,1);
                }
            }
        }
        //console.log(sendingArr)
        if(sendingArr.length==$scope.data.length){
            $scope.all = 2;

        }else{
            $scope.all = 1;

        }
        if(sendingArr.length>0){
            $scope.clear = 1
        }else{
            $scope.clear = 2
        }

    }
    $scope.changeAll = function (code) {
        if(code==1){
            for(var a=0;a<$scope.data.length;a++){
                $scope.data[a].eachFlag = true;
                sendingArr.push($scope.data[a]);
            }
            $scope.all = 2
        }else if(code==2){
            for(var b=0;b<$scope.data.length;b++){
                $scope.data[b].eachFlag = false;
            }
            sendingArr = [];
            $scope.all = 1;
        }
        console.log(sendingArr)
        }
$scope.shenqing = function () {
    if(sendingArr.length==0){
        mui.alert('没有数据更改!','警告','确认');
    }else{
        mainService.setLjsq(sendingArr);
        $location.path('/loujianshenqingPage')
    }
}


}]);